<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>集合</title>
    <script src="js/traceur.js"></script>
    <script src="js/bootstrap.js"></script>
    <script type="module">
        //设计特定的位来保存
        let buffer = new ArrayBuffer(80);
        let view = new DataView(buffer);
        view.setInt32(8,22,false);
        var number = view.getInt32(8,false);
        console.log(number); // "22"

        var buffer1 = new ArrayBuffer(80);
        var typed_array = new Float64Array(buffer1);
        typed_array[4] = 11;
        console.log(typed_array.length); // 10
        console.log(typed_array[4]); // 11


        //set方法
        let set = new Set("Hello!!!");
        set.add(12); //向集合中插入12，集合为 Helo! 12
        console.log(set.has("!")); //判断集合中是否有！字符 true
        console.log(set.size); //6
        set.delete(12); //删除12
        console.log(...set);
        set.clear(); //删除集合所有的值

        //weakset
        let weakset = new WeakSet();
        (function(){
            let a = {};
            //不能插入值，如果想有值，读取set设计的集合
            weakset.add(a);
        })();
        //这里'a'是从weakset收集的垃圾
        console.log(weakset.size); // "undefined"
        //console.log(...weakset); //异常被抛出
        //weakset.clear(); //异常,没有这样的方法

        //map方法
        let map = new Map();
        let o = {n: 1};
        map.set(o, "A"); //增加值为o，9
        map.set("2", 9);
        console.log(map.has("2")); // 判断值中有2，true
        console.log(map.get(o)); //获取键为o的值
        console.log(...map);
        map.delete("2"); //删除键和值为2
        map.clear(); //删除这个map
        let map_1 = new Map([[1, 2], [4, 5]]);
        console.log(map_1.size); //键的长度


        //weakMap
        let weakmap = new WeakMap();
        (function(){
            let o = {n: 1};
            //可以通过set方法插入数据
            weakmap.set(o, "A");
        })();
        let s = {m: 1};
        weakmap.set(s, "B");
        console.log(weakmap.get(s));
        //console.log(...weakmap); //异常被抛出
        weakmap.delete(s);
        //weakmap.clear(); //异常，没有这个函数
        let weakmap_1 = new WeakMap([[{}, 2], [{}, 5]]); //无法插入
        console.log(weakmap_1.size); //undefined
    </script>
</head>
<body>

</body>
</html>